package com.chaoyinsu.controller;// 访问第一个数据库的t_user表

import com.chaoyinsu.common.DataSourceType;
import com.chaoyinsu.common.TargetDataSource;
import com.chaoyinsu.config.DataSourceManagement;
import com.chaoyinsu.entity.User;
import com.chaoyinsu.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping(value = "/user_list")
    public List<User> showUserList(){
        System.out.println(DataSourceType.MYSQL_DATASOURCE1.name());
        List<User> list = userService.list();
        return list;
    }

    @GetMapping(value = "/user_list2")
    // 将注解标注在方法上，表示此方法使用数据源2
    @TargetDataSource(value = DataSourceType.MYSQL_DATASOURCE2)
    public List<User> showUserList2(){
        List<User> list = userService.list();
        return list;
    }

}

